home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / log_tcp_6.0alpha.shar / fix_options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-02  |  1.3 KB  |  52 lines

  1.  /*
  2.   * Routine to disable IP-level socket options. This code was taken from 4.4BSD
  3.   * rlogind source, but all mistakes in it are my fault.
  4.   *
  5.   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  6.   */
  7.  
  8. #ifndef lint
  9. static char sccsid[] = "@(#) fix_options.c 1.1 93/03/07 22:48:02";
  10. #endif
  11.  
  12. #include <sys/types.h>
  13. #include <sys/param.h>
  14. #include <netinet/in.h>
  15. #include <netdb.h>
  16. #include <stdio.h>
  17. #include <syslog.h>
  18.  
  19. #include "log_tcp.h"
  20.  
  21. /* fix_options - get rid of IP-level socket options */
  22.  
  23. fix_options(client)
  24. struct from_host *client;
  25. {
  26. #ifdef IP_OPTIONS
  27.     unsigned char optbuf[BUFSIZ / 3], *cp;
  28.     char    lbuf[BUFSIZ], *lp;
  29.     int     optsize = sizeof(optbuf), ipproto;
  30.     struct protoent *ip;
  31.  
  32.     if ((ip = getprotobyname("ip")) != 0)
  33.     ipproto = ip->p_proto;
  34.     else
  35.     ipproto = IPPROTO_IP;
  36.  
  37.     if (getsockopt(0, ipproto, IP_OPTIONS, (char *) optbuf, &optsize) == 0
  38.     && optsize != 0) {
  39.     lp = lbuf;
  40.     for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
  41.         sprintf(lp, " %2.2x", *cp);
  42.     syslog(LOG_NOTICE,
  43.            "connect from %s with IP options (ignored):%s",
  44.            hosts_info(client), lbuf);
  45.     if (setsockopt(0, ipproto, IP_OPTIONS, (char *) 0, optsize) != 0) {
  46.         syslog(LOG_ERR, "setsockopt IP_OPTIONS NULL: %m");
  47.         clean_exit(client);
  48.     }
  49.     }
  50. #endif
  51. }
  52.